# -*- coding: utf-8 -*-
# @Time:2021/07/08 21:29
# @Author:Cindy
from flask import Flask, request
from flask_restful import Resource, Api
from flask_sqlalchemy import SQLAlchemy
from flask_cors import CORS
import logging

# 实例化一个flask服务
app = Flask(__name__)
api = Api(app)
# 解决跨域
CORS(app, supports_credentials=True)

username = 'root'
pwd = '123456'
ip = '192.168.1.108'
port = '3306'
database = 'students'
app.config['SQLALCHEMY_DATABASE_URI'] = \
    f'mysql+pymysql://{username}:{pwd}@{ip}:{port}/{database}?charset=utf8'
db = SQLAlchemy(app)
app.logger.setLevel(logging.DEBUG)


def router():
    """
    路由管理
    :return:
    """
    from apis.testcases import TestCaseService
    from apis.task import TaskService
    api.add_resource(TestCaseService, '/testcase')
    api.add_resource(TaskService, '/task')


if __name__ == '__main__':
    # # 删除表
    # db.drop_all()
    # # 创建表
    # db.create_all()
    # # 添加数据
    # data1 = TestCase(id=11, nodeid='node1', remark='remark1')
    # data2 = TestCase(id=2, nodeid='node2', remark='remark2')
    # data3 = TestCase(id=3, nodeid='node3', remark='remark3')
    # data4 = TestCase(id=4, nodeid='node4', remark='remark4')
    # data5 = TestCase(id=5, nodeid='node5', remark='remark5')
    # data6 = TestCase(id=6, nodeid='node6', remark='remark6')
    # for data in(data1, data2, data3, data4, data5, data6):
    #     db.session.add(data)
    # db.session.add(data1)
    # db.session.commit()
    router()
    app.run(debug=True)
